import { Propagation, Isolation } from "../db"
import wrapInTransaction from "../db/wrapInTransaction"

export function Transactional(
  propagation: Propagation = Propagation.REQUIRED,
  isolation: Isolation = Isolation.DEFAULT
): MethodDecorator {
  return (target: any, methodName: string | symbol, descriptor: TypedPropertyDescriptor<any>) => {
    descriptor.value = wrapInTransaction(descriptor.value, propagation, isolation)
  }
}
